package com.thread.thread;

/**
 * @author wangyingjie
 * @date
 * @remark
 */
public class ThreadJoin extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(getName()+"===> "+i);
        }
    }

    public static void main(String[] args) throws InterruptedException {//主线程
        ThreadJoin threadJoin2 = new ThreadJoin();
        threadJoin2.start();//子线程0
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+"===> "+i);
            if (i == 20) {
                ThreadJoin threadJoin = new ThreadJoin();
                threadJoin.start();//子线程1
                //main线程调用子线程1的join()，在子线程1执行完之前，main线程会阻塞，所以该时间只有子线程0和子线程1并发
                threadJoin.join();
            }
        }
    }
}
